<?php
/* * ******************************************************************************************************************************* */

// AGREGAR CAJA CONTACTO
/* * ******************************************************************************************************************************* */
function caja_video() {
    global $post;
    $custom = get_post_custom($post->ID);
    $link = $custom["link-Cvideo"][0];
    ?>
    <label>Link del video: </label>
    <input type="text" name="link-Cvideo" size="60" value="<?php echo $link; ?>"/><br/>
    <label style="font-size: 10px; font-style: italic;">Ejemplo: http://www.youtube.com/embed/qBDVyedY1OA</label>
    <?php
}

// Estos son los inserts de los campos
function guardar_caja_video() {
    global $post;
//    update_post_meta($post->ID, "link-Cvideo", $_POST["link-Cvideo"]);


    $custom = get_post_custom($post->ID);

    $datos = array(
        array('nombre' => "link-Cvideo", 'old' => $custom["link-Cvideo"][0], 'new' => $_POST["link-Cvideo"])
    );

    foreach ($datos as $dato) {

        if ($dato['new'] && $dato['new'] != $dato['old']) {
            update_post_meta($post->ID, $dato['nombre'], $dato['new']);
        } elseif ('' == $dato['new'] && $dato['old']) {
            delete_post_meta($post->ID, $dato['nombre'], $dato['old']);
        }
    }
}

function mostrar_caja_video($id) {
    $custom = get_post_custom($id);
    $link = $custom["link-Cvideo"][0];
    ?>
    <div class="box-widget caja-video <?php echo $post->ID; ?>">
        <?php echo do_shortcode('[youtube_sc url=' . $link . ' width=585 height=380 rel=0 fs=1]'); ?>
    </div>
    <?php
}
?>
